<?php
/**
 * Created by PhpStorm.
 * User: mars
 * Date: 2019/1/19
 * Time: 12:44 PM
 */

namespace api\controllers;


use yii\filters\auth\HttpBearerAuth;
use yii\rest\ActiveController;
use yii\rest\Controller;
use yii\web\Response;
use Yii;
class BaseController extends ActiveController
{
    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;//默认浏览器打开返回json
        unset($behaviors['authenticator']);
        $behaviors['corsFilter'] = [
            'class' => \yii\filters\Cors::className(),
            'cors'  => [
                'Origin'                           => static::allowedDomains(),
                'Access-Control-Request-Method'    => ['POST', 'PUT', 'GET', 'OPTIONS', 'DELETE'],
//                'Access-Control-Allow-Credentials' => true,
                'Access-Control-Max-Age'           => 86400,
                'Access-Control-Request-Headers'   => ['*'],
            ],
        ];

        $behaviors['authenticator'] = [
            'class'  => HttpBearerAuth::className(),
            'except' => [
                'OPTIONS',
                'user/login',
                'login',
                'notify',
//                'POST user/login0',
                'login0',
            ],
        ];

        return $behaviors;
    }


    public static function allowedDomains()
    {
        return ['*'];
    }

    public function beforeAction($action)
    {
        $cdn       = Yii::$app->get('cdn');
        $cdn->host = Yii::$app->feehi->website_url;

//        var_dump($cdn->host);
        return parent::beforeAction($action); // TODO: Change the autogenerated stub
    }

    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
    }

}